package com.fluidops.datacatalog.reltables.sim.entity;

import java.util.Collection;

import com.fluidops.datacatalog.reltables.labelbase.DomainSizeDescriptor;
import com.fluidops.datacatalog.reltables.model.Entity;

public class DomainDependantWeight implements IEntitySimilarity{

	private DomainSizeDescriptor dsd;
	
	public DomainDependantWeight(DomainSizeDescriptor dsd) {
		this.dsd = dsd;
	}
	
	@Override
	public double calcEntitySimilarity(Entity e1, Entity e2) {
		double similarity = 0d;
		
		Collection<String> labels1 = e1.getLabels();
		Collection<String> labels2 = e2.getLabels();
		
		for(String l1 : labels1){
			if(labels2.contains(l1) && domainSize(l1) != 0){
				similarity += 1d / ((double)domainSize(l1));
			}
		}
		
		return similarity;
	}
	
	private int domainSize(String label){
		return dsd.getDomainSize(label);
	}
	
}
